<?php
require_once(dirname(dirname(__FILE__)) . '/app.php');
header('Content-Type: application/xml; charset=UTF-8');

$daytime = strtotime(date('Y-m-d'));
$condition = array( 
		'team_type' => 'normal',
		"begin_time <= {$daytime}",
		"end_time > {$daytime}",
		);
$teams = DB::LimitQuery('team', array(
			'condition' => $condition,
			'order' => 'ORDER BY sort_order DESC, id DESC',
			));
$groups = option_category('group', false, false);

$oa = array();
$si = array(
		'sitename' => $INI['system']['sitename'],
		'wwwprefix' => $INI['system']['wwwprefix'],
		'imgprefix' => $INI['system']['imgprefix'],
		);

foreach($teams AS $one) {
	$city = Table::Fetch('category', $one['city_id']);
	$group = Table::Fetch('category', $one['group_id']);
	$item = array();
	$item['loc'] = $si['wwwprefix'] . "/teams.php?id={$one['id']}";
	$item['data'] = array();
	$item['data']['display'] = array();
	$item['data']['shops']['shop'] = array();

	$o = array();
	$o['website'] = $INI['system']['sitename'];
	$o['siteurl'] = $INI['system']['wwwprefix'];
	($o['city'] = $city['name']) || ($o['city'] = '全国');
	$o['title'] = $one['title'];
	//$o['class'] = $groups[$one['group_id']];
	$o['image'] = $si['imgprefix']  .'/static/' . $one['image'];
	$o['startline'] = $one['begin_time'];
	$o['deadline'] = $one['end_time'];
	$o['value'] = $one['market_price'];
	$o['price'] = $one['team_price'];
	//if ( $one['market_price'] > 0 ) {
	//	$o['rebate'] = moneyit(10*$one['team_price']/$one['market_price']);
	//} else {
	//	$o['rebate'] = '0';
	//}
	$o['bought'] = abs(intval($one['now_number']));
	
	$o['tag']=$groups[$one['group_id']];
	$o['priority']=$one['sort_order'];
    $x=array();
	$p = Table::Fetch('partner', $one['partner_id']);
	$x['name']= $p['title'];
	//$x['tel'] = $p['tel'];
	$x['addr']=$p['address'];


	$item['data']['display'] = $o;
    $item['data']['shops']['shop'] = $x;
	$oa[] = $item;
}

Output::XmlBaidu($oa);
